<?php require_once('./core/import.php'); ?>
<?php
#获取参数
$Username=Functions::FormArgs('Username');
$Password=Functions::FormArgs('Password');
$IsSetCookiesExpire=Functions::FormArgs('IsSetCookiesExpire');
$Captcha=Functions::FormArgs('Captcha');

#验证码
if(strtolower($Captcha)!=Session::Get(User::SESSIONNAME_LOGIN_CAPTCHA))
{
    Functions::JsAlert('验证码错误,请重新输入');
    Functions::JsLocation('login.php');
    exit();
}

#验证登录权限
if($Username==NULL||$Password==NULL)
{
    Functions::JsAlert('用户名或密码错误');
    Functions::JsHistory(-1);
}
else
{
    $User=new User($Username,$Password);
    {
        if($User->IsLogin())
        {
            header('location:main.php');
        }
        else
        {
            $Result=$User->Verify();
            if($Result=='Normal')
            {
                $User->Login($IsSetCookiesExpire=='TRUE' ? time()+60*60*27*30:NULL);
                header('location:main.php');
            }
            else
            {
                if($Result=='Locked')
                {
                    Functions::JsAlert('用户被锁定请联系管理员');
                    Functions::JsLocation('login.php');
                }
                else
                {
                    Functions::JsAlert('用户名密码错误');
                    Functions::JsLocation('login.php');
                }
            }
        }
    }
    $User=NULL;
}
?>